package br.com.corsini.database;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jose.corsini on 13/01/14.
 */
public class DaoTableHelper {

    private static final String TEXT_TYPE = " TEXT";
    private static final String COMMA_SEP = ",";

    protected String tableName;
    protected String idName;
    protected Map<String,String> columns;

    public DaoTableHelper(String tableName, int columnsSize)
    {
        this.tableName = tableName;
        this.columns = new HashMap<String, String>(columnsSize);
    }

    protected void addId(String idName)
    {
        idName = idName;
    }

    /**
     *
     * @param columnName: nome na variável estática do filho
     * @param columnId: nome da coluna no BD
     */
    protected void addColumn(String columnName, String columnId)
    {
        columns.put(columnName, columnId);
    }

    public void createTable()
    {
        StringBuilder sqlCreate = new StringBuilder();
        sqlCreate.append("CREATE TABLE ");
        sqlCreate.append(this.tableName);
        sqlCreate.append(" (");
        sqlCreate.append(idName);
        sqlCreate.append(" INTEGER PRIMARY KEY");

        //Cria colunas
        for(Map.Entry<String, String> entry : columns.entrySet()) {
            String value = entry.getValue();
            sqlCreate.append(COMMA_SEP);
            sqlCreate.append(value);
            sqlCreate.append(" ");
            sqlCreate.append(TEXT_TYPE);
        }
        sqlCreate.append(")");
    }





}



